package cn.sightsnow.zh.controller;

import cn.sightsnow.zh.service.TrackService;
import cn.sightsnow.zh.entity.Location;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@Api(tags = "轨迹相关接口")
@RestController
@RequestMapping("/track")
@Slf4j
public class TrackController {
    TrackService trackService;

    public TrackController(TrackService trackService) {
        this.trackService = trackService;
    }

    @ApiOperation("获取定位信息")
    @GetMapping
    public Page<Location> getTrackLocation(
            @RequestParam(value = "targetId", required = false) String targetId,
            @RequestParam(value = "routeId", required = false) String routeId,
            @PageableDefault(size = 20) Pageable pageable) {
        return trackService.findLocationByTargetId(targetId, routeId, pageable);
    }
    @ApiOperation("接收定位信息")
    @PostMapping
    public void postTrackLocation(@RequestBody @Validated Location location) {
        log.info("接收到定位信息LocationId：{}",location.getLocationId());
        trackService.insertLocation(location);
    }
}
